import socket

# 配置参数
LOCAL_HOST = '127.0.0.1'
PORT = 5000
BUFFER_SIZE = 4096

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((LOCAL_HOST, PORT))
print("Listening on port: ", PORT)

while True:
    data, addr = s.recvfrom(BUFFER_SIZE)

    # 打印接收到的数据并将其回传给客户端
    print('Received from ', addr[0], ':', addr[1], ' -> Data: ', data.decode())
    s.sendto(data, addr)